<!--# include virtual="/admin/common/html/header.html"-->

<body>
<article class="page-container">
	<form action="/user_service/user/addUserAndUserInfo.do"  method="post" class="form form-horizontal" id="form-member-add">	
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>登录账号：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="hidden" class="input-text" value="" placeholder="" id="userId" name="userId" disabled="true">
				<input type="hidden" class="input-text" value="" placeholder="" id="infoId" name="infoId" disabled="true">
				<input type="text" class="input-text" value="" placeholder="" id="account" name="account">
			</div>
		</div>	
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>网站昵称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="userName" name="userName">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>真实姓名：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="realName" name="realName">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>手机：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="phone" name="phone">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>邮箱：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" placeholder="@" name="email" id="email">
			</div>
		</div>
		<div class="row cl"  >
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>性别：</label>
			<div class="formControls col-xs-8 col-sm-9 skin-minimal radio-sex" >
				<div class="radio-box ">
					<input name="sex" type="radio" id="sex-1" value="1" checked>
					<label for="sex-1">男</label>
				</div>
				<div class="radio-box ">
					<input name="sex" type="radio" id="sex-2" value="2" >
					<label for="sex-2">女</label>
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>年龄：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" placeholder="@" name="age" id="age">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>积分：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" placeholder="" name="integral" id="integral">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>阅读券：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" placeholder="" name="coupons" id="coupons">
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<button onClick="article_save_submit();" class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存并提交审核</button>
				<button onClick="removeIframe();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
			</div>
		</div>
	</form>
</article>

	<!--# include virtual="/admin/common/html/_footer.html"-->
	<script type="text/javascript">
			
		/*var srcString=$(window.parent.document).find("#testIframe").attr("src");	*/				
		function GetQueryString(name){
     		var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     		var r = window.location.search.substr(1).match(reg);
     		if(r!=null)return  unescape(r[2]); return null; 
		}
		
		$(function() {
			var userId = GetQueryString("userId");
			console.log("from.html="+userId);
			if(userId != "" && userId !=null) {				
				$.post("/user_service/user/get.do", {"userId": userId}, function(result) {
					if(result.resultCode == 200 && result.data != null) {
						console.log(result.data);
						$("input[name='userId']").attr("disabled",false);
						$("input[name='infoId']").attr("disabled",false);
						$("input[name='infoId']").val(result.data.infoId);
						$("input[name='userId']").val(userId);
						$("input[name='account']").val(result.data.account);
						$("input[name='account']").attr("readonly",true);
						$("input[name='userName']").val(result.data.userName);
						$("input[name='realName']").val(result.data.realName);
						$("input[name='identifyNumber']").val(result.data.identifyNumber);
						$("input[name='phone']").val(result.data.phone);
						$("input[name='email']").val(result.data.email);
						if(result.data.sex == "1"){
							$(".radio-sex").find("input[value='1']").parent().addClass('checked');
							$(".radio-sex").find("input[value='2']").parent().removeClass('checked');
							$(".radio-sex").find("input[value='1']").attr("checked","checked");
						}else if(result.data.sex == "2"){
							//console.log($(".radio-sex").find("input[value='2']").parent());
							$(".radio-sex").find("input[value='2']").parent().addClass('checked');
							$(".radio-sex").find("input[value='1']").parent().removeClass('checked');
							$(".radio-sex").find("input[value='2']").attr("checked","checked");
						}
						$("input[name='email']").val(result.data.email);
						$("input[name='age']").val(result.data.age);
						$("input[name='integral']").val(result.data.integral);
						$("input[name='coupons']").val(result.data.coupons);
					} else {
						layer.msg(result.message, {icon: 2,time: 2000});
					}
				});
			}
		});

		$(function() {
			var userId = GetQueryString("userId");
			
			$('.skin-minimal input').iCheck({
				checkboxClass: 'icheckbox-blue',
				radioClass: 'iradio-blue',
				increaseArea: '20%'
			});
			//表单验证
			$("#form-member-add").validate({
				rules: {
					account: {
						required: true,
					},
					userName: {
						required: true,
					},
					realName: {
						required: true,
					},
					phone: {
						required: true,
					},
					email: {
						required: true,
					},
					age: {
						required: true,
					},
					integral: {
						required: true,
					},
					coupons: {
						required: true,
					}					
				},
				onkeyup: false,
				focusCleanup: true,
				success: "valid",
				submitHandler: function(form) {
					if(userId != "" && userId != null) {
						$("#form-member-add").attr("action","/user_service/user/updateUserAndUserInfo.do");
						console.log(form.action);
					}
					var data = $(form).serialize();
					console.log('data=' + data);
					$.post(form.action, data, function(result) {
						if(result.resultCode == 200) {
							layer.msg(result.message, {icon: 1,time: 2000}, function() {
								window.parent.location.href = "/admin/modules/member/member-list.html";
							});
						} else {
							layer.msg(result.message, {icon: 2,time: 2000});
						}
					});
				}
			});
		});
	</script>
</body>
</html>